package com.shuoyue.ycgk.ui.questionbank;

import com.shuoyue.ycgk.base.BaseModel;
import com.shuoyue.ycgk.base.BasePresenter;
import com.shuoyue.ycgk.base.BaseResult;
import com.shuoyue.ycgk.base.BaseView;
import com.shuoyue.ycgk.entity.QuestionParent;
import com.shuoyue.ycgk.net.RetrofitClient;
import com.shuoyue.ycgk.net.base.ApiSubscriber;
import com.shuoyue.ycgk.net.gsondefaultadapter.Optional;

import java.util.List;

import io.reactivex.Observable;
import retrofit2.http.Field;

public interface UserPaperQuestionContract {
    interface View extends BaseView {

        void setQuestions(List<QuestionParent> specialPager);
    }

    class Presenter extends BasePresenter<View> {
        Model model = new Model();

        /**
         * @param type 1：专项训练,2,模考 3 真题 4估分  5 自由组卷用专项(结构不一致,不卸载这里)
         */
        public void getQuestions(int pagerId, int type, String paperType) {
            getQuestions(pagerId, type, paperType, 0);
        }


        public void getQuestions(int pagerId, int type, String paperType, int evaId) {
            Observable<BaseResult<List<QuestionParent>>> observable = null;

            switch (type) {
                case 1:
                    observable = model.getSpecialQuestions(pagerId,
                            paperType);
                    break;
                case 2:
                    observable = model.getMokQuestions(pagerId,
                            paperType);
                    break;
                case 3:
                    observable = model.getSetQuestions(pagerId,
                            paperType);
                    break;
                case 4:
                    observable = model.getEstimateQuestion(pagerId, evaId);
                    break;
//                case 5:
//                    observable = model.get(userAnser);
//                    break;
            }
            if (observable != null)
                apply(observable)
                        .subscribe(new ApiSubscriber<Optional<List<QuestionParent>>>(mView, this) {
                            @Override
                            public void onNext(Optional<List<QuestionParent>> specialPagerOptional) {
                                super.onNext(specialPagerOptional);
                                mView.setQuestions(specialPagerOptional.getIncludeNull());
                            }
                        });
        }


    }

    class Model extends BaseModel {
        Observable<BaseResult<List<QuestionParent>>> getSpecialQuestions(int pagerId,
                                                                         String type) {
            return RetrofitClient.getInstance().getApi().getSpecialQuestions(pagerId,
                    type);
        }

        Observable<BaseResult<List<QuestionParent>>> getSetQuestions(int pagerId,
                                                                     String type) {
            return RetrofitClient.getInstance().getApi().getSetQuestions(pagerId,
                    type);
        }

        Observable<BaseResult<List<QuestionParent>>> getMokQuestions(int pagerId,
                                                                     String type) {
            return RetrofitClient.getInstance().getApi().getMokQuestions(pagerId,
                    type);
        }

        Observable<BaseResult<List<QuestionParent>>> getEstimateQuestion(int pagerId, int evaId) {
            return RetrofitClient.getInstance().getApi().getEstimateQuestions(pagerId);
        }


    }
}
